﻿#ifndef TCPSERVER_H
#define TCPSERVER_H

#if _MSC_VER >= 1600
#pragma execution_character_set("utf-8")
#endif

#define WM_SOCKET  WM_USER+1000

#include <QWidget>
#include <QMessageBox>
#include <QDialog>
#include <iostream>
#include <Windows.h>
#include <winsock.h>
#include <QDebug>
#include <QObject>
#include <mutex>

#pragma comment(lib,"ws2_32.lib")

class TCPServer : public QWidget
{
public:
    TCPServer(QWidget *parent = nullptr);

    int Initialize(int Port);
    int Send(std::string message);

    void ReceivedClear();
    void ReceivedPush(std::string str);
    std::string ReceivedPop();
    int ReceivedSize();

protected:
     bool nativeEvent(const QByteArray &eventType, void *message, long *result);

private:
    char mBuf[4096]{0};
    int n;
    SOCKET ServerSocket;
    sockaddr_in ServerAddr;
    SOCKET ClientSocket;
    sockaddr_in ClientAddr;
    std::vector<std::string> m_Received;
    std::mutex m_mutex;

};

#endif // TCPSERVER_H
